/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    timer_test.c
 *  @brief   TIMER testcase source file
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#include "printf.h"
#include "hal_api.h"
#include "device_timer.h"

#define TEST_TIMER_DFT_MS (500)


static void one_shot_timer_irq_callback(void *arg)
{
	uint32_t timer_id = *((uint32_t *)arg);
	printf("[TIMER%lu]: one_shot_timer_irq_callback\r\n", timer_id);
}

static void period_timer_irq_callback(void *arg)
{
	uint32_t timer_id = *((uint32_t *)arg);
	printf("[TIMER%lu]: period_timer_irq_callback\r\n", timer_id);
}

int32_t test_timer(void)
{
	uint32_t timer_id = 0;

	printf("\r\n[TIMER]: TEST START\r\n");
	printf("ONE SHOT TIMER TEST\r\n");
	for (timer_id = DW_TIMER_0_ID; timer_id <= DW_TIMER_5_ID; timer_id++)
	{
		Hal_Timer_StartOneshot(timer_id, TEST_TIMER_DFT_MS * 2, one_shot_timer_irq_callback);
		printf("[TIMER%lu]: start 1s oneshot timer\r\n", timer_id);
		Hal_Cnt_DelayMs(TEST_TIMER_DFT_MS * 2 + 100);
	}

	printf("PERIOD TIMER TEST\r\n");
	for (timer_id = DW_TIMER_0_ID; timer_id <= DW_TIMER_5_ID; timer_id++)
	{
		printf("[TIMER%lu]: start period timer\r\n", timer_id);
		Hal_Timer_StartPeriod(timer_id, TEST_TIMER_DFT_MS, period_timer_irq_callback);
		Hal_Cnt_DelayMs(TEST_TIMER_DFT_MS + 1000);
		Hal_Timer_StopPeriod(timer_id);
	}

	printf("[TIMER]: TEST END\r\n");

	return 0;
}
